package com.petecat.interchan.base.warning.config.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.petecat.interchan.base.project.entity.EsEwarningHardwareConfig;
import com.petecat.interchan.base.warning.config.entity.EsEwarningHardWare;
import com.petecat.interchan.base.warning.config.entity.EsWarningNoticeVO;
import com.petecat.interchan.base.warning.config.entity.WarningEmpl;
import com.petecat.interchan.base.warning.config.service.IWarningConfigService;
import com.petecat.interchan.core.constans.Global;
import com.petecat.interchan.core.controller.BaseController;
import com.petecat.interchan.protocol.GlobalHeader;
import com.petecat.interchan.protocol.Result;
import com.petecat.interchan.protocol.base.config.dto.BsWarningConfigAddDTO;
import com.petecat.interchan.protocol.base.config.dto.BsWarningConfigQryDTO;
import com.petecat.interchan.protocol.base.config.dto.BsWarningConfigUpdDTO;
import com.petecat.interchan.protocol.base.config.vo.BsWarningConfigQryVO;
import com.petecat.interchan.protocol.base.config.vo.BsWarningConfigTreeVO;
import com.petecat.interchan.protocol.base.config.vo.BsWarningConfigUpdVO;
import com.petecat.interchan.protocol.data.PageVO;
import com.petecat.interchan.protocol.sso.companyempl.vo.BsSmsQryVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@Api("预警配置管理")
@RequestMapping("/base/warningconfig")
public class WarningConfigController extends BaseController{
	
	@Autowired
	private IWarningConfigService configService;
	
	@SuppressWarnings("unchecked")
	@ApiOperation("分页查询预警配置信息")
	@GetMapping("/queryWarningConfigByPage")
	public Result<PageVO<BsWarningConfigQryVO>> queryWarningConfigByPage(@ModelAttribute BsWarningConfigQryDTO bsWarningConfigQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsWarningConfigQryDTO.setUserId(userInfo.getUserId());
		PageVO<BsWarningConfigQryVO> pageVO = configService.queryWarningConfigByPage(bsWarningConfigQryDTO);
		return (Result<PageVO<BsWarningConfigQryVO>>) Result.ok(pageVO);
	}
	

	@SuppressWarnings("unchecked")
	@ApiOperation("查询预警配置Tree")
	@GetMapping("/queryWarningConfigTree")
	public Result<PageVO<BsWarningConfigTreeVO>> queryWarningConfigTree(@ModelAttribute BsWarningConfigQryDTO bsWarningConfigQryDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		bsWarningConfigQryDTO.setUserId(userInfo.getUserId());
		PageVO<BsWarningConfigTreeVO> pageVO = configService.queryWarningConfigTree(bsWarningConfigQryDTO);
		return (Result<PageVO<BsWarningConfigTreeVO>>) Result.ok(pageVO);
	}
	


	@ApiOperation(value = "新增预警配置基本信息", notes = "新增")
	@PostMapping(value = "/saveWarningConfig")
	public Result<?> saveWarningConfig(@RequestBody BsWarningConfigAddDTO bsWarningConfigAddDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		configService.saveWarningConfig(bsWarningConfigAddDTO, userInfo.getUserId());
		return Result.ok();
	}
	

	@ApiOperation(value = "修改预警配置信息", notes = "修改")
	@PutMapping(value = "/updateWarningConfig")
	public Result<?> updateWarningConfig(@RequestBody BsWarningConfigUpdDTO bsWarningConfigUpdDTO,
			@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		configService.updateWarningConfig(bsWarningConfigUpdDTO, userInfo.getUserId());
		return Result.ok();
	}
	
	
	@SuppressWarnings("unchecked")
	@ApiOperation(value = "查询预警配置模块")
	@GetMapping(value = "/queryWarningConfig")
	public Result<BsWarningConfigUpdVO> queryWarningConfig(@RequestParam String configId,@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		BsWarningConfigUpdVO warningConfigUpdVO= configService.queryWarningConfig(configId,userInfo.getUserId());
		return (Result<BsWarningConfigUpdVO>) Result.ok(warningConfigUpdVO);
	}
	
	@ApiOperation(value = "通过预警配置Id删除预警配置信息")
	@DeleteMapping(value = "/removeWarningConfigByConfigId")
	public Result<?> removeWarningConfigByConfigId(@RequestParam String configId){
		configService.removeWarningConfigByConfigId(configId);
		return Result.ok();
	}
	
	@ApiOperation(value = "通过预警配置Id修改预警配置状态信息")
	@PutMapping(value = "/updateStatusConfigById")
	public Result<?> updateStatusConfigById(@RequestParam String configId,@RequestParam String projectId){
		configService.updateStatusConfigById(configId,projectId);
		return Result.ok();
	}
	
	@SuppressWarnings("unchecked")
	@ApiOperation("查询ES预警消息通知")
	@GetMapping("/queryEsWarningNotice")
	public Result<List<EsWarningNoticeVO>> queryEsWarningNotice(@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		List<EsWarningNoticeVO> listVo = configService.queryEsWarningNotice(userInfo.getUserId());
		return (Result<List<EsWarningNoticeVO>>) Result.ok(listVo);
	}
	
	@SuppressWarnings("unchecked")
	@ApiOperation("通过规则ID查询对应的预警信息")
	@GetMapping("/getWarningByRuleId")
	public Result<List<EsEwarningHardWare>> getWarningByRuleId(@RequestParam String ruleId,@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		List<EsEwarningHardWare> listVo = configService.getWarningByRuleId(ruleId,userInfo.getUserId());
		return (Result<List<EsEwarningHardWare>>) Result.ok(listVo);
	}
	
	@ApiOperation("根据ID修改指定的 是否已读状态")
	@GetMapping("/updateEsWarningReadStatusById")
	public Result<?> updateEsWarningReadStatusById(@RequestParam(required=false) List<String> ids,@RequestParam(required=false) String ruleId,@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		configService.updateEsWarningReadStatusById(ids,ruleId,userInfo.getUserId());
		return Result.ok();
	}
	
	@SuppressWarnings("unchecked")
	@ApiOperation("通过EsID查询对应的预警人员")
	@GetMapping("/getWarningEmplByEsId")
	public Result<PageVO<WarningEmpl>> getWarningEmplByEsId(@RequestParam String esId,@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		PageVO<WarningEmpl> listVo = configService.getWarningEmplByEsId(esId,userInfo.getUserId());
		return (Result<PageVO<WarningEmpl>>) Result.ok(listVo);
	}
	
	@SuppressWarnings("unchecked")
	@ApiOperation("通过EsID查询对应的规则信息")
	@GetMapping("/getWarningRuleInfoByEsId")
	public Result<EsEwarningHardwareConfig> getWarningRuleInfoByEsId(@RequestParam String esId,@ApiIgnore @RequestHeader(name = Global.GLOBAL_HEADER, required = false) String header) {
		GlobalHeader userInfo = this.getUserInfo(header, true);
		EsEwarningHardwareConfig listVo = configService.getWarningRuleInfoByEsId(esId,userInfo.getUserId());
		return (Result<EsEwarningHardwareConfig>) Result.ok(listVo);
	}
	
}
